/**
 * 解析路由路径
 * Created by Mr.K on 1/8/2021.
 */
import {
  isExternal
} from '@/utils/validate'
import path from 'path'

/**
 * resolvePath 返回真实路由path
 * @param {String} basePath
 * @param {Object} route
 * @returns {String}
 */
export function resolvePath(basePath, route) {
  let routePath = route.path
  if (route.meta && route.meta.realPath) {
    routePath = route.meta.realPath
  }
  if (isExternal(basePath)) {
    return basePath
  }
  if (isExternal(routePath)) {
    return routePath
  }
  return path.resolve(basePath, routePath)
}

/**
 * isEmptyPath 是否为空路由地址
 * @param {Object} route
 * @returns {Boolean}
 */
export function isEmptyPath(route) {
  if ((route.redirect && route.redirect === 'noRedirect') || !route.path || route.path === '#') {
    return true
  }
  return false
}
